import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/layout/index.vue'
import Login from '../views/login/index.vue'
import Home from '../views/home'
import Cookies from 'js-cookie'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
	meta:{title:"首页",icon:'home'},
    name: 'home',
    component: Layout,
	redirect:"/home",
	children:[
		{
			path:"home",
			name:"myhome",
			component:Home
		}
	]
  },
  //配置商品模块的路由
  {
    path: '/product',
    name: 'product',
	meta:{title:"商品",icon:"shangpin"},
    component: Layout,
  	redirect:"/product/plist",
  	children:[
  		{
  			path:"product/list",
  			name:"plist",
			meta:{title:"商品列表",icon:'liebiao1'},
  			component: () => import(/* webpackChunkName: "about" */ '../views/product/product/list.vue')
  		},
		{
			path:"product/add",
			name:"padd",
			meta:{title:"商品添加",icon:"new"},
			component: () => import(/* webpackChunkName: "about" */ '../views/product/product/add.vue'),
			redirect:"/product/product/add/info",
			children:[
				{
					path:"info",
					name:"info",
					component: () => import(/* webpackChunkName: "about" */ '../views/product/product/components/ProductInfo.vue')
				},
				{
					path:"sales",
					name:"sales",
					component: () => import(/* webpackChunkName: "about" */ '../views/product/product/components/ProductSales.vue')
				},
				{
					path:"attr",
					name:"attr",
					component: () => import(/* webpackChunkName: "about" */ '../views/product/product/components/ProductAttr.vue')
				},
				{
					path:"asso",
					name:"asso",
					component: () => import(/* webpackChunkName: "about" */ '../views/product/product/components/ProductAsso.vue')
				}
			]
		},
		{
			path:"brand/list",
			name:"brandlist",
			meta:{title:"品牌管理",icon:"pinpaitemai"},
			component: () => import(/* webpackChunkName: "about" */ '../views/product/brand/list.vue')
		},
		{
			path:"cat/list",
			name:"procatlist",
			meta:{title:"商品分类",icon:"fenlei1"},
			component: () => import(/* webpackChunkName: "about" */ '../views/product/productCat/list.vue')
		},
		{
			path:"type/list",
			name:"producttype",
			meta:{title:"商品类型",icon:"liebiao1"},
			component: () => import(/* webpackChunkName: "about" */ '../views/product/productType/list.vue')
		}
  	]
  },
  //配置商品模块的路由
  {
    path: '/product',
    name: 'product',
  	meta:{title:"商品",icon:"shangpin"},
    component: Layout,
  	redirect:"/product/plist",
  	children:[
  		{
  			path:"product/list",
  			name:"plist",
  			meta:{title:"商品列表",icon:'liebiao1'},
  			component: () => import(/* webpackChunkName: "about" */ '../views/product/product/list.vue')
  		},
  		{
  			path:"product/add",
  			name:"padd",
  			meta:{title:"商品添加",icon:"new"},
  			component: () => import(/* webpackChunkName: "about" */ '../views/product/product/add.vue'),
  			redirect:"/product/product/add/info",
  			children:[
  				{
  					path:"info",
  					name:"info",
  					component: () => import(/* webpackChunkName: "about" */ '../views/product/product/components/ProductInfo.vue')
  				},
  				{
  					path:"sales",
  					name:"sales",
  					component: () => import(/* webpackChunkName: "about" */ '../views/product/product/components/ProductSales.vue')
  				},
  				{
  					path:"attr",
  					name:"attr",
  					component: () => import(/* webpackChunkName: "about" */ '../views/product/product/components/ProductAttr.vue')
  				},
  				{
  					path:"asso",
  					name:"asso",
  					component: () => import(/* webpackChunkName: "about" */ '../views/product/product/components/ProductAsso.vue')
  				}
  			]
  		},
  		{
  			path:"brand/list",
  			name:"brandlist",
  			meta:{title:"品牌管理",icon:"pinpaitemai"},
  			component: () => import(/* webpackChunkName: "about" */ '../views/product/brand/list.vue')
  		},
  		{
  			path:"cat/list",
  			name:"procatlist",
  			meta:{title:"商品分类",icon:"fenlei1"},
  			component: () => import(/* webpackChunkName: "about" */ '../views/product/productCat/list.vue')
  		},
  		{
  			path:"type/list",
  			name:"producttype",
  			meta:{title:"商品类型",icon:"liebiao1"},
  			component: () => import(/* webpackChunkName: "about" */ '../views/product/productType/list.vue')
  		}
  	]
  },
  {
    path: '/login',
    name: 'login',
	hidden:true,  //隐藏
    component: Login
  },
  {
    path: '/404',
    name: '404',
	hidden:true,  //隐藏
    component: () => import(/* webpackChunkName: "about" */ '../views/404.vue')
  }
]

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//添加路由守卫
router.beforeEach((to,from,next)=>{
	let loginType = Cookies.get("loginToken");
	if(!loginType){
		//未登录     loginType的值为false，就进了if，那不就是说明if中写未登录的逻辑
		//去登录不要拦截，去用户中心才拦截
		if(to.path == "/login"){
			next();
		}else{
			next("/login")
			return;
		}
	}
	next();
})

export default router
